﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.iss.inventory.Entity;

namespace com.iss.inventory.Controllers
{
    public class PersonalInformationController
    {
        public PersonalInformationController() { }

        public String[] getEmpByID(String lblEmpID)
        {
            
            InvManagementEntities IME = new InvManagementEntities();
            var eID = Convert.ToInt32(lblEmpID);
            Employee e = IME.Employees.First<Employee>(x => x.EmployeeID == eID);
            Department d = IME.Departments.First<Department>(y => y.DeptID == e.DeptID);
            String[] employee = { e.Name, e.Role, Convert.ToString(e.DeptID), Convert.ToString(d.HeadID), Convert.ToString(e.Phone), e.Email, e.Password };
            return employee;
        }

        public String updateEmp(String lblEmployeeID, String txtPhone, String txtEmail)
        {
            InvManagementEntities IME = new InvManagementEntities();
            //main function
            var tempID = Convert.ToInt32(lblEmployeeID);
            Employee emp = IME.Employees.First<Employee>(x => x.EmployeeID == tempID);
            emp.Phone = Convert.ToInt32(txtPhone); emp.Email = txtEmail;
            IME.SaveChanges();
            return "Update Personal Information Successfully";
        }

        public String updatePassword(String lblEmployeeID, String txtPassword) {
            InvManagementEntities IME = new InvManagementEntities();
            var tempID = Convert.ToInt32(lblEmployeeID);
            Employee emp = IME.Employees.First<Employee>(x => x.EmployeeID == tempID);
            emp.Password = txtPassword;
            IME.SaveChanges();
            return "Change password successfully";
        }
    }
}
